package com.group.flagtivities;

import android.app.Activity;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.TextView;

public class TypePicker extends Activity implements OnClickListener {
	
	private static TextView athletics;
	private static TextView computer_science;
	private static TextView fine_arts;
	private static TextView foreign_language;
	private static TextView humanities;
	private static TextView mathematics;
	private static TextView social;
	
	public static final int REQUEST_CODE = 0;
	public static final int ATHLETICS = 1;
	public static final int COMPUTER_SCIENCE = 2;
	public static final int FINE_ARTS = 3;
	public static final int FOREIGN_LANGUAGE = 4;
	public static final int HUMANITIES = 5;
	public static final int MATHEMATICS = 6;
	public static final int SOCIAL = 7;
	
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.typepicker);
        
        findViews();
        configureType(athletics, getResources().getColor(R.color.red_light), getResources().getColor(R.color.red_dark));
        configureType(computer_science, getResources().getColor(R.color.orange_light), getResources().getColor(R.color.orange_dark));
        configureType(fine_arts, getResources().getColor(R.color.yellow_light), getResources().getColor(R.color.yellow_dark));
        configureType(foreign_language, getResources().getColor(R.color.green_light), getResources().getColor(R.color.green_dark));
        configureType(humanities, getResources().getColor(R.color.blue_light), getResources().getColor(R.color.blue_dark));
        configureType(mathematics, getResources().getColor(R.color.indigo_light), getResources().getColor(R.color.indigo_dark));
        configureType(social, getResources().getColor(R.color.violet_light), getResources().getColor(R.color.violet_dark));
        
        
        TextUtil.setFont((ViewGroup) findViewById(R.id.typepicker), getAssets());
    }
	
	private void findViews() {
		athletics = (TextView) findViewById(R.id.athletics);
        computer_science = (TextView) findViewById(R.id.computer_science);
        fine_arts = (TextView) findViewById(R.id.fine_arts);
        foreign_language = (TextView) findViewById(R.id.foreign_language);
        humanities = (TextView) findViewById(R.id.humanities);
        mathematics = (TextView) findViewById(R.id.mathematics);
        social = (TextView) findViewById(R.id.social);
	}
	
	private void configureType(TextView view, int startColor, int endColor) {
		Drawable drawable = ImageUtil.colorSwatch(40, 40, startColor, endColor);
        drawable.setBounds(0, 0, 40, 40);
        view.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null);
        view.setCompoundDrawablePadding(10);
        view.setBackgroundColor(getResources().getColor(R.color.gray_light));
        view.setOnClickListener(this);
	}
	
	@Override
	public void onClick(View view) {
		switch (view.getId()) {
		case R.id.athletics:
			this.setResult(TypePicker.ATHLETICS);
			finish();
			break;
		case R.id.computer_science:
			this.setResult(TypePicker.COMPUTER_SCIENCE);
			finish();
			break;
		case R.id.fine_arts:
			this.setResult(TypePicker.FINE_ARTS);
			finish();
			break;
		case R.id.foreign_language:
			this.setResult(TypePicker.FOREIGN_LANGUAGE);
			finish();
			break;
		case R.id.humanities:
			this.setResult(TypePicker.HUMANITIES);
			finish();
			break;
		case R.id.mathematics:
			this.setResult(TypePicker.MATHEMATICS);
			finish();
			break;
		case R.id.social:
			this.setResult(TypePicker.SOCIAL);
			finish();
			break;
		case R.id.close:
			this.setResult(TypePicker.RESULT_CANCELED);
			finish();
			break;
		}
	}
	
}
